function Game(ele) {// element 元素/节点
     this.ele = document.querySelector(ele)
    this.map = new Map(this.ele) //将地图标签对象传递给map构造函数，里面设置宽度高度等
    this.map.create() 

    this.food=new Food(this.ele)
    this.food.create()
    this.snake=new Snake(this.ele)
    this.snake.create()
    // this.init()
}
/* Game.prototype.init()=function(){
    this.start()
    this.stop()
} */
Game.prototype.start=function(){
    let t=setInterval(()=>{
        this.snake.move()
        let snakeX=this.snake.snakeObj[0].x*20
        let snakeY=this.snake.snakeObj[0].y*20
        let foodX=this.food.foodX
        let foodY=this.food.foodY
        if(snakeX==foodX&snakeY==foodY){
            let last=this.snake.snakeObj[this.snake.snakeObj.length-1]
            this.snake.snakeObj.push( { 
                x:last.x,
                y:last.y, 
                color:last.color,
                ele:null})
            this.snake.create()
            this.food.move()
        }
    },150)
Game.prototype.stop=function(){
   clearInterval(t)

}
    document.addEventListener('keydown',(e)=>{
         e=e||window.event
         switch (e.keyCode){
            case 38:
             this.snake.direction='top'
             break;
            case 40:
             this.snake.direction='bottom'
             break;
            case 37:
                if(this.snake.direction=='right'){
                   alert('no')
                }
             this.snake.direction='left'
             break;
            case 39:
             this.snake.direction='right'
             break;
            default:
                 break;
         }
    })
}